<!DOCTYPE html>
<html>
<head>
    <title>挂号--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>
 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
    $(function () {       
		$('#backid').click(function(){
				window.location.href="index.html";
		 });
    });
    </script>
</head>
<body>
<form  id="updateForm" action="" method="post" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">姓名</td>
        <td><input type="text" name="hosrName" value="" required/></td>
    </tr>

    <tr>
        <td width="10%" class="tableleft">身份证号</td>
        <td><input type="text" name="hosrIdcar" value="" required/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">社保号</td>
        <td><input type="text" name="hosrMedical" value="" required/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">挂号费</td>
        <td><input type="text" name="hosrRegprice" value="" required/>元</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">联系电话</td>
        <td><input type="text" name="hosrPhone" value=""/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">是否自费</td>
        <td><input type="radio" name="hosrSelfprice" value="1" checked/>否&nbsp;&nbsp;&nbsp;<input type="radio"
                                                                                                  name="hosrSelfprice"
                                                                                                  value="0"/>是
        </td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">性别</td>
        <td><input type="radio" name="hosrSex" value="1" checked/>男&nbsp;&nbsp;&nbsp;<input type="radio"
                                                                                            name="hosrSex"
                                                                                            value="0"/>女
        </td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">年龄</td>
        <td><input type="text" name="hosrAge" value="" required/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">职业</td>
        <td><input type="text" name="hosrWork" value="" required/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">初复诊</td>
        <td><input type="radio" name="hosrLookdoctor" value="0" checked/>初诊&nbsp;&nbsp;&nbsp;
            <input type="radio" name="hosrLookdoctor" value="1"/>复诊
        </td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">状态</td>
        <td>
            <input type="radio" name="hosrState" value="0" checked/>挂号&nbsp;&nbsp;&nbsp;
            <input type="radio" name="hosrState" value="1"/>已住院&nbsp;&nbsp;&nbsp;
<!--            <input type="radio" name="hosrState" value="2"/>已出院&nbsp;&nbsp;&nbsp;-->
<!--            <input type="radio" name="hosrState" value="3"/>已退号&nbsp;&nbsp;&nbsp;-->
        </td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">所挂科室</td>
        <td>
            <select id="dKeshi" name="dKeshi" onchange="loadDoctor()">
                <option value="急诊科">急诊科</option>
                <option value="急诊科">骨科</option>
                <option value="急诊科">血液科</option>
            </select>
        </td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">指定医生</td>
        <td>
            <select id="doctorName" name="doctorName">
                <option value="程俊">程俊</option>
                <option value="欧阳雨露">欧阳雨露</option>
                <option value="王博">王博</option>
            </select>
        </td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">备注</td>
        <td><textarea name="hosrRemark"></textarea></td>
    </tr>
    <tr>
        <td colspan="2">
            <center>
                <button id="update" class="btn btn-primary" type="button">更新</button> &nbsp;&nbsp;
                <button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
            </center>
        </td>
    </tr>
</table>
</form>
</body>
</html>
<script src="/layer/layer.js"></script>
<script src="/Js/getParameter.js"></script>
<script type="text/javascript">
    $(function () {
        //根据地址获取doctorId,如果null则执行增加，否则执行更新
        let url = document.location.toString();//获取URL
        let hosrId = url.GetValue("hosrId");
        let pageNum = url.GetValue("pageNum");
        let pageSize = url.GetValue("pageSize");
        //加载科室和医生信息
        loadData();
        //根据id回显医生信息到页面
        queryById(hosrId);
        //更新
        $("#update").click(function (){
            //加载
            var windowId = layer.load(0, {time: 1000});
            //alert($("#updateForm").serialize())
            $.post("/hospital/hosRegister/"+hosrId,$("#updateForm").serialize()+"&_method=PUT",function (vo){
                if (vo.code == 200){
                    layer.close(windowId);
                    layer.msg(vo.msg);
                    window.location.href = "/registration/index.html?pagaNum="+pageNum+"&pageSize="+pageSize;
                }else {
                    layer.close(windowId);
                    layer.msg(vo.msg);
                }
            },"json");
        });


    });

    //科室查询
    function loadData() {
        $.get("/hospital/hosRegister/keshi", {}, function (vo) {
            let str = "";
            let list = vo.list;
            for (let i = 0; i < list.length; i++) {
                let obj = list[i];
                let dKeshi = obj.dKeshi;
                str += '<option value="' + dKeshi + '  ">' + dKeshi + '</option>';
            }
            $("#dKeshi").html(str);
            loadDoctor();
        });
    }

    //更具科室联动查询医生信息
    function loadDoctor() {
        //获取被选中的option标签
        var keshi = $('select  option:selected').val();
        $.get("/hospital/hosRegister/doctorName/" + keshi, {}, function (vo) {
            let list = vo.list;
            let str = "";
            for (let i = 0; i < list.length; i++) {
                let obj = list[i];
                let dName = obj.dName;
                str += '<option value="' + dName + '">' + dName + '</option>';
            }
            $("#doctorName").html(str);
        })
    }
    //回显函数
    function queryById(hosrId) {
        $.get("/hospital/hosRegister/"+hosrId, {} ,function (vo){
            let obj = vo.obj;
            let dId = obj.dId;
            let hosrName = obj.hosrName;
            let hosrIdcar = obj.hosrIdcar;
            let hosrMedical = obj.hosrMedical;
            let hosrRegprice = obj.hosrRegprice;
            let hosrPhone = obj.hosrPhone ;
            let hosrSelfprice = obj.hosrSelfprice;
            let hosrSex = obj.hosrSex ;
            let hosrAge = obj.hosrAge;
            let hosrWork = obj.hosrWork;
            let hosrLookdoctor = obj.hosrLookdoctor;
            let dKeshi = obj.dKeshi;
            let hosrTime = obj.hosrTime;
            let hosrRemark = obj.hosrRemark;
            let hosrState = "";
            if (obj.hosrState == 0) {
                $("input[name='hosrState'][value='0']").attr("checked",true);
            } else if (obj.hosrState == 1) {
                $("input[name='hosrState'][value='1']").attr("checked",true);
            } else if (obj.hosrState == 2) {
                $("input[name='hosrState'][value='2']").attr("checked",true);
            } else if (obj.hosrState == 3) {
                $("input[name='hosrState'][value='3']").attr("checked",true);
            }
            let hosrRecode = obj.hosrRecode;
            let doctorName = obj.doctorName;

            $("input[name='hosrName']").val(hosrName);
            $("input[name='hosrIdcar']").val(hosrIdcar);
            $("input[name='hosrRegprice']").val(hosrRegprice );
            $("input[name='hosrMedical']").val(hosrMedical);
            $("input[name='hosrPhone']").val(hosrPhone);

            $("input[name='hosrAge']").val(hosrAge);
            $("input[name='hosrWork']").val(hosrWork);

            $("input[name='dKeshi']").val(dKeshi);
            $("input[name='doctorName']").val(doctorName);
            $("textarea[name='hosrRemark']").val(hosrRemark);
            $("input[name='hosrState']").val(hosrState);
            $("input[name='hosrTime']").val(hosrTime);

            if (hosrSex){
                $("input[name='hosrSex'][value='1']").attr("checked",true);
            }else {
                $("input[name='hosrSex'][value='0']").attr("checked",true);
            }
            if (hosrSelfprice){
                $("input[name='hosrSelfprice'][value='1']").attr("checked",true);
            }else {
                $("input[name='hosrSelfprice'][value='0']").attr("checked",true);
            }

            if (hosrLookdoctor){
                $("input[name='hosrLookdoctor'][value='1']").attr("checked",true);
            }else {
                $("input[name='hosrLookdoctor'][value='0']").attr("checked",true);
            }



        });
    }
    String.prototype.GetValue = function (para) {
        let reg = new RegExp("(^|&)" + para + "=([^&]*)(&|$)");
        let r = this.substr(this.indexOf("\?") + 1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
</script>